<?php  
class ControllerModulehot extends Controller {
	protected function index() {
		$this->language->load('module/hot');

      	$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->load->model('catalog/article');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');
		$this->load->model('tool/image');
		
		$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
			
		$this->data['articles'] = array();
		
		$results = $this->model_catalog_article->getFeaturedArticles($this->config->get('hot_limit'));
			
		foreach ($results as $result) {
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}
			
			$strs=explode(" ",$result['name']);
			if(count($strs)>5){
				$name=substr($result['name'],0,strpos($result['name'],$strs[5])-1)."...";
			}else{
				$name=$result['name'];
			}
			
			$strs=explode(" ",$result['meta_description']);
			if(count($strs)>10){
				$des=substr($result['meta_description'],0,strpos($result['meta_description'],$strs[10])-1)."...";
			}else{
				$des=$result['meta_description'];
			}
			$name_mask = $result['name'];
			
			
			
			$this->data['articles'][] = array(
				'article_id'    => $result['article_id'],
				'name'    		=> $name,
				'model'   		=> $result['model'],
				'image'			=> $this->model_tool_image->resize($image, 660, 300),				
				'thumb'   		=> $this->model_tool_image->resize($image, 60, 60),
				'href'    		=> $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/article&article_id=' . $result['article_id']),
				'des'			=> $des,
				'name_mask' 	=> $result['name'],
				'des_mask'		=> $result['meta_description']
			);
		}

		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}
		
		$this->id = 'hot';

		if ($this->config->get('hot_position') == 'home') {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/hot_home.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/hot_home.tpl';
			} else {
				$this->template = 'default/template/module/hot_home.tpl';
			}
		} else {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/hot.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/module/hot.tpl';
			} else {
				$this->template = 'default/template/module/hot.tpl';
			}
		}
		
		$this->render();
	}
}
?>